package com.foreveross.taskservice.taskcache.redis;

import javax.annotation.Resource;

import com.foreveross.taskservice.common.model.AbstractTaskModel;
import com.foreveross.taskservice.taskcache.TaskAddQueryIndexApplication;
import com.foreveross.taskservice.taskcache.TaskRollbackConvertorApplication;
import com.foreveross.taskservice.taskcache.redis.core.TaskRedisTemplate;
/**
 * 实现某些属性的统一注入
 * @author guokenye
 *
 */
public class BaseRedisTaskCache extends AbstractRedisTaskCache{
	@Resource(name="taskRedisTemplate")
	private TaskRedisTemplate taskRedisTemplate;
	@Override
	protected TaskRedisTemplate getTaskRedisTemplate() {
		// TODO Auto-generated method stub
		return taskRedisTemplate;
	}
	
	@Resource(name="airFreightAddQueryIndexApplicationImpl")
	private TaskAddQueryIndexApplication<AbstractTaskModel> airTaskAddQueryIndexApplication;//注入航空运价领域的查询索引
	@Resource(name="airFreightRollbackConvertorApplicationImpl")
	private TaskRollbackConvertorApplication<AbstractTaskModel> airRollbackConvertorApplication;
	
	
	@Override
	protected TaskAddQueryIndexApplication<AbstractTaskModel> getAddQueryIndexApplication(
			AbstractTaskModel model) {
		//判断模型的具体类型与接口要求的具体类型是否一致
		if(isEqualsClass(model,this.airTaskAddQueryIndexApplication)){
			return this.airTaskAddQueryIndexApplication;
		}
		
		return null;
	}
	@Override
	protected TaskRollbackConvertorApplication<AbstractTaskModel> getTaskRollbackConvertorApplication(
			AbstractTaskModel rollTask, AbstractTaskModel cacheTask) {
		if(isEqualsClass(rollTask,this.airRollbackConvertorApplication) && 
				isEqualsClass(cacheTask,this.airRollbackConvertorApplication)
				){
			return this.airRollbackConvertorApplication;
		}
		return null;
	}
	
	private boolean isEqualsClass(AbstractTaskModel model,TaskAddQueryIndexApplication<AbstractTaskModel> query){
		return query==null?false:model.getClass().equals(query.getTaskModelClass());
	}
	private boolean isEqualsClass(AbstractTaskModel model,TaskRollbackConvertorApplication<AbstractTaskModel> convert){
		return convert==null?false:model.getClass().equals(convert.getTaskModelClass());
	}


	
}
